#!/bin/bash

# execute script in a subshell so it
# can be controlled by a timeout
# send a TERM signal after 15 minutes
# send a KILL signal after 20 minutes

timeout -s 15 -k 1200 900 bash << EOS
    set -x
    {% if ansible_pkg_mgr == "yum" %}
    sed -i -e "/proxy\=/d" /etc/yum.conf
    {% endif %}

    {{ ansible_pkg_mgr }} update -y

    {% if "undercloud" in item.path %}
    {{ ansible_pkg_mgr }} install -y libselinux-python* python*-libselinux
    {{ ansible_pkg_mgr }} install -y git
    mkdir -p /opt/{{ undercloud_user }}/new/tripleo-ci
    git clone https://opendev.org/openstack/tripleo-ci /opt/stack/new/tripleo-ci
    {% endif  %}
    {% if "overcloud" in item.path  %}
    rm -rf /etc/puppet/modules/*
    rm -rf /opt/{{ undercloud_user }}
    {% if release in ['newton', 'ocata', 'pike'] %}
    {{ ansible_pkg_mgr }} install -y openstack-puppet-modules
    {% else  %}
    {{ ansible_pkg_mgr }} install -y puppet-tripleo
    {% endif  %}
    ln -s /usr/share/openstack-puppet/modules/* /etc/puppet/modules/
    {% endif  %}

EOS
